package com.shopping.service.impl;

import java.util.List;
import java.util.Map;

import com.shopping.bean.OrderGoods;
import com.shopping.bean.OrderType;
import com.shopping.bean.Page;
import com.shopping.dao.OrderGoodsDao;
import com.shopping.dao.impl.OrderGoodsDaoImpl;
import com.shopping.service.OrderGoodsService;

public class OrderGoodsServiceImpl implements OrderGoodsService {

	@Override
	public Page<OrderGoods> findAll(Map<String, String[]> condition) {
		OrderGoodsDao ogd = new OrderGoodsDaoImpl();
		List<OrderGoods> list = ogd.selectAll(condition);
		
		int pageSum = ogd.selectTotalRows(condition);
		int pageNum = 1;
		int pageSize = 5;
		
		try {
			pageNum = Integer.parseInt(condition.get("pageNum")[0]);
		}catch(Exception o) {
			o.printStackTrace();
		}
		try {
			pageSize = Integer.parseInt(condition.get("pageSize")[0]);
		}catch(Exception o) {
			o.printStackTrace();
		}
		System.out.println(pageNum);
		System.out.println(pageSize);
		Page<OrderGoods> page = new Page<OrderGoods>(list,pageNum,pageSize,pageSum);
		return page;
	}

	

	@Override
	public List<OrderType> selectAllOrderByUserId(int userId) {
		OrderGoodsDao ogd = new OrderGoodsDaoImpl();
		return ogd.selectOrderByUserId(userId);
	}



	@Override
	public int insertOrder(Map<String, String[]> condition) {
		OrderGoodsDao ogd = new OrderGoodsDaoImpl();
		return ogd.insertGoogsOnCar(condition);
	}

}
